package top.wanzc.java.basic.jdk9.to17.feature;

public class SwitchEnhancement {
	
	public static void main(String[] args) {
		System.out.println(getSeason("xiaocao"));
		switchCase2();
	}
	
	
	public static String getSeason(String month) {
		return switch (month) {
		    case "march", "april", "may"            -> "春天";
		    case "june", "july", "august"           -> "夏天";
		    case "september", "october", "november" -> "秋天";
		    case "december", "january", "february"  -> "冬天";
		    default -> "unknown";
		};
	}
	
	public static void switchCase1() {
		int month = 3;
        String monthName = switch(month) {
            case 3,4,5 -> "春季";
            case 6,7,8 -> "夏季";
            case 9,10,11 -> "秋季";
            case 12,1,2 -> "冬季";
            // default -> "error";
            default -> throw new IllegalArgumentException("月份有误！");
        };
        System.out.println("monthName = " + monthName);
	}
	
	public static void switchCase2() {
		int week = 7;
		String weekName = switch (week) {
		case 1 -> "Monday";
		case 2 -> "Tuesday";
		case 3 -> "Wednesday";
		case 4 -> "Thursday";
		case 5 -> "Friday";
		case 6 -> "Saturday";
		case 7 -> {
			System.out.println("Weekend!");
			yield "Sunday";
		}
		default -> {
			System.out.println("Week number is between 1 and 7.");
			yield "Error";
		}
		};
		System.out.println("weekName = " + weekName);
	}
	
	// preview功能，暂时还不能使用
	/*public static String formatterSwitch(Object o) {
	    return switch (o) {
	        case Integer i -> String.format("int %d", i);
	        case Long l  -> String.format("long %d", l);
	        case Double d -> String.format("double %f", d);
	        case String s -> String.format("String %s", s);
	        default    -> o.toString();
	    };
	}*/


}
